# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=pgmodeler
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.5
pkgrel=1
pkgdesc="PostgreSQL Database Modeler: an open source CASE tool for modeling PostgreSQL databases (mingw-w64)"
url="https://pgmodeler.io"
license=('GPL3')
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-postgresql"
         "${MINGW_PACKAGE_PREFIX}-qt6-svg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")

source=("${_realname}-${pkgver}.tar.gz::https://github.com/${_realname}/${_realname}/archive/v${pkgver}.tar.gz"
        '0001-pgmodeler-1.0.2-libgui-inc.patch'
        '0002-pgmodeler-1.0.2-no-check-update.patch'
        '0003-pgmodeler-1.0.2-fix-global-attributes.patch')
sha256sums=('461b8493e112e894b40522cd01f02b2b4898f86c4410a9f37259e0d949eb9659'
            'f658ed0129b0402c8d91b44f62498e35f9c1af87ae14ae1a4030f0b9e7b8bf78'
            'ceae3c5dadf80754ffdea133a53a1bd28bca9e837af0c495d52f5651c8e89fef'
            '5806e049bf306cf61bbc87880c1bc5e5d42c749170d8ab0f3e3dd9a6b475ac45')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}

    patch -Np1 -i "${srcdir}"/0001-pgmodeler-1.0.2-libgui-inc.patch
    patch -Np1 -i "${srcdir}"/0002-pgmodeler-1.0.2-no-check-update.patch
    patch -Np1 -i "${srcdir}"/0003-pgmodeler-1.0.2-fix-global-attributes.patch
}

build() {
    msg2 "Will be in future"
}

package() {
    cd ${srcdir}/${_realname}-${pkgver}

    "${MINGW_PREFIX}"/bin/qmake6.exe CONFIG+=release \
          PREFIX="${pkgdir}${MINGW_PREFIX}" \
          BINDIR="${pkgdir}${MINGW_PREFIX}"/bin \
          PRIVATEBINDIR="${pkgdir}${MINGW_PREFIX}"/bin \
          PRIVATELIBDIR="${pkgdir}${MINGW_PREFIX}"/bin \
          PLUGINSDIR="${pkgdir}${MINGW_PREFIX}"/lib/pgmodeler/plugins \
          CONFDIR="${pkgdir}${MINGW_PREFIX}"/etc/pgmodeler \
          SHAREDIR="${pkgdir}${MINGW_PREFIX}"/share/pgmodeler \
          DOCDIR="${pkgdir}${MINGW_PREFIX}"/share/doc/pgmodeler \
          LANGDIR="${pkgdir}${MINGW_PREFIX}"/share/pgmodeler/lang \
          SAMPLESDIR="${pkgdir}${MINGW_PREFIX}"/share/pgmodeler/samples \
          SCHEMASDIR="${pkgdir}${MINGW_PREFIX}"/share/pgmodeler/schemas \
          PGSQL_LIB="${MINGW_PREFIX}"/bin/libpq.dll \
          PGSQL_INC="${MINGW_PREFIX}"/include \
          XML_INC="${MINGW_PREFIX}"/include/libxml2 \
          XML_LIB="${MINGW_PREFIX}"/bin/libxml2-2.dll \
          NO_UPDATE_CHECK=MSYS2doesthis \
          QMAKE_CXXFLAGS_RELEASE+="${CXXFLAGS} ${CPPFLAGS}" \
          pgmodeler.pro

    make

    make INSTALL_ROOT="" install

    rm "${pkgdir}${MINGW_PREFIX}/bin/"lib*.dll.a
    rm "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/"{LICENSE,README.md}

    install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

